package com.zhs.gccs.mbtiles.server;

import android.text.TextUtils;
import android.util.Log;

//mbtile?model=xm&type=pdf&layer=cia_w&x={x}&y={y}&z={z}
public class RequestParamParser {
    public static WmsParam parseParam(String url, String method, String params) {
        Log.d(">>>mapbox", "request:" + params);
        ///mbtile?model=xm&type=pdf&layer=cia_w&x=843&y=388&l=10
        if (!TextUtils.isEmpty(url)
                && url.contains("?")
                && url.contains("model=")
                && url.contains("layer=")
                && url.contains("type=")
                && url.contains("x=")
                && url.contains("y=")
                && url.contains("z=")) {
            WmsParam wmsParam = new WmsParam();
            String urlParams = url.substring(url.indexOf("?") + 1);
            String[] split = urlParams.split("&");
            for (int i = 0; i < split.length; i++) {
                String item = split[i];
                String[] param = item.split("=");
                try {
                    if (param[0].equals("model")) {
                        wmsParam.setModel(param[1]);
                    } else if (param[0].equals("type")) {
                        wmsParam.setType(param[1]);
                    } else if (param[0].equals("layer")) {
                        wmsParam.setLayer(param[1]);
                    }else if (param[0].equals("x")) {
                        wmsParam.setX(Integer.parseInt(param[1]));
                    } else if (param[0].equals("y")) {
                        wmsParam.setY(Integer.parseInt(param[1]));
                    } else if (param[0].equals("z")) {
                        wmsParam.setZ(Integer.parseInt(param[1]));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return wmsParam;
        }
        return null;
    }
}
